RNDIS/ECM (网卡)


1. 概述

ECM 以太网控制模型(Ethernet Networking Control Model)用于在设备和主机之间传输以太网数据包。
RNDIS 即RemoteNDIS,既是远程网络驱动接口规范,是微软基于ECM定义的USB网络协议。


2. 板端内核配置(device)

本节将分别介绍在linux 平台以及uboot 使用rndis的配置方法

  1. linux 平台配置

    -> Device Drivers
        -> USB Gadget Support
        -> USB Gadget Drivers
            -> Ethernet Gadget (with CDC Ethernet support)
            -> [*]       RNDIS support
    

    如果选上[*] RNDIS support, 则支持RNDIS虚拟网卡

    生成模块:u_ether.ko usb_f_ecm.ko usb_f_ecm_subset.ko usb_f_rndis.ko g_ether.ko(依赖 libcomposite )

    加载顺序:

    u_ether.ko

    usb_f_ecm.ko

    usb_f_ecm_subset.ko

    usb_f_rndis.ko

    udc-msb250x.ko/dwc3.ko

    g_ether.ko

  2. uboot 平台配置

    开启配置

    1. CONFIG_CMD_USBSTART

      -> Command line interface
          -> USB commands
          [*] usbstart
      
    2. SSTAR_UTMI_POWERON

      -> Command line interface
          -> USB commands
          [*] Power on UTMI first
      

    配置环境变量

    setenv usbnet_devaddr 00:30:78:00:00:02

    setenv usbnet_hostaddr 00:50:14:00:00:02

    setenv ethact usb_ether

    setenv ipaddr 10.10.70.3

    setenv netmask 255.0.0.0

    setenv gatewayip 10.10.70.1

    setenv cdc_connect_timeout 20

    启动usb device

    usbstart

    连上设备可以执行ctrl-c,然后执行ping回到命令行


3. 主机端配置(host)

3.1. linux 主机

x CONFIG_USB_NET_RNDIS_HOST:
x
x This option enables hosting "Remote NDIS" USB networking links,
x as encouraged by Microsoft (instead of CDC Ethernet!) for use in
x various devices that may only support this protocol.  A variant
x of this protocol (with even less public documentation) seems to
x be at the root of Microsoft's "ActiveSync" too.
x 
x Avoid using this protocol unless you have no better options.
x The protocol specification is incomplete, and is controlled by
x (and for) Microsoft; it isn't an "Open" ecosystem or market.  
x 
x Symbol: USB_NET_RNDIS_HOST [=m]
x Type  : tristate
x Prompt: Host for RNDIS and ActiveSync devices
x   Location:
x     -> Device Drivers
x       -> Network device support (NETDEVICES [=y])
x         -> USB Network Adapters (USB_NET_DRIVERS [=m])
x           -> Multi-purpose USB Networking Framework (USB_USBNET [=m])
x   Defined at drivers/net/usb/Kconfig:383
x   Depends on: NETDEVICES [=y] && USB_NET_DRIVERS [=m] && USB_USBNET [=m]
x   Selects: USB_NET_CDCETHER [=m]
x   Selected by: USB_NET_RNDIS_WLAN [=n] && NETDEVICES [=y] && WLAN [=n] && USB [=m] && CFG80211 [=m]

相关驱动:

cdc-ether.ko usbusbnet.ko rndis_host.ko

3.2. window 主机

  1. 在设备管理器选择需要更新RNDIS驱动的设备

  2. 右键“更新驱动程序”

  3. 选择第二项“浏览我的计算机以查找驱动程序软件”

  4. 选择“从计算机的设备驱动程序选取”

  5. 选择网络适配器

  6. 厂商选择:Microsoft, 型号选择远程NDIS 兼容设备


4. 网卡使用

  1. 设备端

    网卡名usb0(与linux主机端命名方式一致),配置方式:ifconfig usb0 192.168.1.2

  2. 主机端

    跟正常网卡使用方式一致,需与设备端网卡ip网段保持一致

5. 动态分配ip

可以在连接上host的时候自动给host分配ip

配置对象: device

工具需求: udhcpd

创建leases文件:

mkdir /var/lib/misc/ -p

touch /var/lib/misc/udhcpd.leases

创建配置文件:udhcpd.conf

# Sample udhcpd configuration file (/etc/udhcpd.conf)

# The start and end of the IP lease block

start 192.168.1.20 #default: 192.168.0.20
end 192.168.1.254 #default: 192.168.0.254

# The interface that udhcpd will use

interface usb0 #default: eth0

# The maximim number of leases (includes addressesd reserved
# by OFFER's, DECLINE's, and ARP conficts

#max_leases 254 #default: 254

配置网卡ip:

ifconfig usb0 192.168.1.19

执行命令:

udhcpd -fS /customer/udhcpd.conf &